package com.ds.lens.flink.monitor.monitorjob.function.detector;

import java.util.Comparator;

public class MonitorEventDetectorComparator implements Comparator<MonitorEventDetector> {
    @Override
    public int compare(MonitorEventDetector o1, MonitorEventDetector o2) {
        if (o1.getMonitorState().getLevel() < o2.getMonitorState().getLevel()) {
            return 1;
        } else if (o1.getMonitorState().getLevel() > o2.getMonitorState().getLevel()) {
            return -1;
        } else {
            return 0;
        }
    }

//    public static void main(String[] args) {
//        List<MonitorEventDetector> list = new ArrayList<>();
//        list.add(ThresholdDetector.builder().metricName("errorCount").aggrEnum(AggregatorEnum.AVG).operator(CompareOperatorEnum.LARGERTHAN).atLeastTimes(1).threshold(10d).state(MonitorStateEnum.NO_DATA).build());
//        list.add(ThresholdDetector.builder().metricName("errorCount").aggrEnum(AggregatorEnum.AVG).operator(CompareOperatorEnum.LARGERTHAN).atLeastTimes(1).threshold(10d).state(MonitorStateEnum.OK).build());
//        list.add(ThresholdDetector.builder().metricName("errorCount").aggrEnum(AggregatorEnum.AVG).operator(CompareOperatorEnum.LARGERTHAN).atLeastTimes(1).threshold(10d).state(MonitorStateEnum.ALARM_LEVEL_4).build());
//        list.add(ThresholdDetector.builder().metricName("errorCount").aggrEnum(AggregatorEnum.AVG).operator(CompareOperatorEnum.LARGERTHAN).atLeastTimes(1).threshold(10d).state(MonitorStateEnum.ALARM_LEVEL_3).build());
//        list.add(ThresholdDetector.builder().metricName("errorCount").aggrEnum(AggregatorEnum.AVG).operator(CompareOperatorEnum.LARGERTHAN).atLeastTimes(1).threshold(10d).state(MonitorStateEnum.ALARM_LEVEL_2).build());
//        list.add(ThresholdDetector.builder().metricName("errorCount").aggrEnum(AggregatorEnum.AVG).operator(CompareOperatorEnum.LARGERTHAN).atLeastTimes(1).threshold(10d).state(MonitorStateEnum.ALARM_LEVEL_5).build());
//        list.add(ThresholdDetector.builder().metricName("errorCount").aggrEnum(AggregatorEnum.AVG).operator(CompareOperatorEnum.LARGERTHAN).atLeastTimes(1).threshold(10d).state(MonitorStateEnum.ALARM_LEVEL_1).build());
//        Collections.sort(list, new MonitorEventDetectorComparator());
//        for (MonitorEventDetector detector : list) {
//            System.out.println(detector.getMonitorState());
//        }
//    }
}

